package com.zfh;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/valid")
public class ValidSession extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();

		HttpSession session = request.getSession();
		out.println("当前session的id是： "+session.getId());
		session.invalidate();//让session过期
		System.out.println("主动设置session过期了");
		out.println("<br>已经主动设置session过期了");
		if (session==null) {
			session = request.getSession();
			out.println("<br>再次获取，查看session的id是： "+session.getId());
		} else {
			out.println("<br>再次直接查看session的id是： "+session.getId());
		}
	}

}
